{include file="Public/header" title="学生列表"/}

<div id="container" class="container-fluid">
    <div class="row-fluid">

        <!-- 左侧导航栏 start -->
        {include file="Public/sidebar"/}
        <!-- 左侧导航栏 end -->

        <div id="content" class="span10">
            <div class="pageTit page-header">
                <h1>学生列表 </h1>

                <div class="opt">
                    <a class="btn btn-info" href="{:U('admin/student/add')}">添加学生</a>
                </div>
            </div>

            <div class="search">
                <form id="searchForm" name="searchform" class="well form-search" action="" method="post">
                      <span>学生姓名：
                        <input type="text" name="search[name]" value="{$search['name']}" placeholder="支持模糊查询"
                               class="input-medium">
                      </span>

                      <span>性别：
                        <select style="width:90px" name="search[sex]">
                            <option value='' selected>全部</option>
                            <option value="男" {if condition="'男' eq $search[sex]" }selected{/if}>男</option>
                            <option value="女" {if condition="'女' eq $search[sex]" }selected{/if}>女</option>
                            {/volist}
                        </select>
                      </span>

                      <span>民族：
                        <input type="text" name="search[nation]" value="{$search['nation']}" placeholder="支持模糊查询"
                               class="input-medium">
                      </span>
                      <span>专业：
                          <select style="width:90px" name="search[major_id]">
                              <option value='0' selected>全部</option>
                              {$major_list = get_list('Major')}
                              {volist name="major_list" id="vo"}
                              <option class="major_option" value="{$vo.Id}" {if
                                      condition="$vo[Id] eq $search[major_id]" }selected{/if}>{$vo.name}</option>
                              {/volist}
                          </select>
                      </span>
                        <span>班级：
                          <select style="width:90px" name="search[class_id]" id="select_class">
                              <option value='0' selected>全部</option>
                              {$class_list = get_list('Class')}
                              {volist name="class_list" id="vo"}
                              <option value="{$vo.Id}" {if condition="$vo[Id] eq $search[class_id]" }selected{/if}>{$vo.name}</option>
                              {/volist}
                          </select>
                          </span>

                    <input type="submit" class="btn btn-info btn-mini" value="搜索" id="search"/>
                    <a href="{:U('admin/student/import')}" target="_blank" class="btn btn-warning btn-mini">导入</a>
                </form>
            </div>

            <div class="dataBox">
                <table class="table table-bordered table-striped center text-center">
                    <thead>
                    <tr>
                        <th class="span1">ID</th>
                        <th class="span2">姓名</th>
                        <th class="span2">性别</th>
                        <th class="span2">民族</th>
                        <th class="span2">出生日期</th>
                        <th class="span2">专业</th>
                        <th class="span2">班级</th>
                        <th class="span3">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {if condition="$student_list"}
                    {foreach name="student_list" item="vo" }
                    <tr>
                        <td><a href="#">{$vo.Id}</a></td>
                        <td>{$vo.name}</td>
                        <td>{$vo.sex}</td>
                        <td>{$vo.nation}</td>
                        <td>{$vo.birthday}</td>
                        <td>{:get_title('Major',$vo['major_id'])}</td>
                        <td>{:get_title('Class',$vo['class_id'])}</td>
                        <td>
                            <a title="编辑" class=" btn btn-mini btn-info js_edit" href="__APP__/admin/Student/edit?id={$vo.Id}">编辑</a>
                            <a title="删除" class=" btn btn-mini btn-danger js_del" href="__APP__/admin/Student/del?id={$vo.Id}">删除</a>
                        </td>
                    </tr>
                    {/foreach}
                    {else/}
                    <tr>
                        <td colspan="13">暂无相关学生信息</td>
                    </tr>
                    {/if}

                    </tbody>
                </table>
            </div>

            {include file="Public/page"/}


        </div>
    </div>
</div>

<script>
    $(document).ready(function () {
        $("#search").click(function () {
            $("#searchForm").submit();
        });
        $(function () {
            $('.btn-danger').click(function () {
                var result = confirm("删除是不可恢复的,你确认要删除吗?");
                if (!result) {
                    return false;
                }
            });
        });
        function class_list(major_id) {
            $.ajax({
                type: "post",
                url: "__APP__/admin/class/class_list",
                async: true,
                data: {
                    id: major_id,
                },
                datatype: "json",
                success: function (data) {
                    var str = "";
                    if (data.status == 0) {
                        $.each(data.data, function (index, item) {
                            str += "<option value=" + item.Id + ">" + item.name + "</option>";
                        });
                        $("#select_class").empty();
                        $("#select_class").append(str);
                    }
                    else {
                        alert(data.data);
                    }
                },
                error: function (data) {
                    alert("数据异常，请刷新页面");
                }
            });
        }
        $(".major_option").click(function () {
            var major_id = $(this).val();
            class_list(major_id);
        });
    });
</script>
{include file="Public/footer"/}